package com.supplychain.scm.core.delay.message;


import com.google.common.collect.Maps;
import org.springframework.util.Assert;

import java.util.Map;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName QueueMessageBuilder
 * @createTime 17:17:00 2022/10/14
 */
public class QueueMessageBuilder<T> {

    private T payload;

    private Map<String, Object> headers;

    public static <T> QueueMessageBuilder<T> withPayload(T payload) {
        Assert.notNull(payload, "payload must not be null");
        QueueMessageBuilder<T> builder = new QueueMessageBuilder<>();
        builder.payload = payload;
        return builder;
    }

    public QueueMessageBuilder<T> headers(Map<String, Object> headers) {
        if (headers == null) {
            headers = Maps.newHashMap();
        }
        this.headers = headers;
        return this;
    }

    public QueueMessage<T> build() {
        return new QueueMessage<>(this.payload, this.headers);
    }

}
